package com.tmsps.common.config;



import org.hibernate.validator.HibernateValidator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;

/**
 * @ClassName: ValidatorAutoConfiguration
 * @Description: 自动注入Validation配置
 *               Fail fast mode
 * @author: geek
 * @date: 2020年06月30日 11:33
 */
@Configuration
@ConditionalOnClass({HibernateValidator.class})
public class ValidatorAutoConfiguration {

    @Bean
    public Validator validator(){
        return Validation.byProvider(HibernateValidator.class)
                .configure()
                .failFast(true)
                .buildValidatorFactory()
                .getValidator();
    }
}
